# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
from PIL import Image
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt

def getnetwork():
    # 图像数据获取
    fashion_mnist = keras.datasets.fashion_mnist
    (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
    # 图像预处理
    class_names = ["上衣","裤子","套头衫","连衣裙","外套","凉鞋","衬衫","运动鞋","包","短靴"]
    train_images = train_images / 255.0
    test_images = test_images / 255.0
    # 构建神经网络
    model = keras.Sequential([
        keras.layers.Flatten(input_shape=(28, 28)),
        keras.layers.Dense(128, activation='relu'),
        keras.layers.Dense(10)
    ])
    # 编译模型
    model.compile(optimizer='adam',
                  loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
                  metrics=['accuracy'])
    # 训练数据
    model.fit(train_images, train_labels, epochs=10)
    # 给出最终模型
    probability_model = tf.keras.Sequential([model,
                                             tf.keras.layers.Softmax()])
    return probability_model
